package com.burt.springcloudeurekaserverdemo;

import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.bootstrap.config.PropertySourceLocator;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.Environment;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.PropertySource;

import java.util.HashMap;
import java.util.Map;

@EnableEurekaServer
@SpringBootApplication
public class SpringCloudEurekaServerDemoApplication {

    public static void main(String[] args) {
        new SpringApplicationBuilder(SpringCloudEurekaServerDemoApplication.class).web(WebApplicationType.SERVLET)
                .run(args);
    }

    @Configuration
    @Order(Ordered.HIGHEST_PRECEDENCE)
    public static class MyPropertySourceLocator implements PropertySourceLocator {

        @Override
        public PropertySource<?> locate(Environment environment) {
            Map<String, Object> source = new HashMap<>();
            source.put("eureka.instance.leaseRenewalIntervalInSeconds", "5");
            source.put("eureka.instance.leaseExpirationDurationInSeconds", "10");
            MapPropertySource propertySource = new MapPropertySource("my-property-source", source);
            return propertySource;
        }
    }
}
